package com.vitabuybuy.tv.ui.mine.talent.live.viewmodel

import androidx.lifecycle.MutableLiveData
import com.library.common.base.BaseViewModel
import com.library.common.base.MessageModel
import com.library.common.ext.rxHttpRequest
import com.library.common.net.error.msg
import com.library.common.toast.XToast
import com.vitabuybuy.tv.dto.LiveNoticeDto
import com.vitabuybuy.tv.dto.SatrtLiveInfoDto
import com.vitabuybuy.tv.network.AuthRepository
import com.vitabuybuy.tv.network.TalentLiveRepository
import java.util.*

class StartLiveViewModel : BaseViewModel() {

    val noticeList = MutableLiveData<MutableList<LiveNoticeDto>>()
    val liveInfoDto = MutableLiveData<SatrtLiveInfoDto>()


    fun uploadImage(path: String) {
        rxHttpRequest {
            onRequest = {
                val it = AuthRepository.upLoadImage(path).await()
                defUI.msgEvent.postValue(MessageModel(1, obj = it))
            }
            onError = {
                XToast.normal(it.msg)
            }
            isShowDialogRequest = true
        }
    }

    fun getNoticeList(pageNumber: Int) {
        rxHttpRequest {
            onRequest = {
                noticeList.value = TalentLiveRepository.getLiveNotice(pageNumber).await()
            }
            onError = {
                XToast.normal(it.msg)
            }
            isLoadingType = true
            isRefresh = pageNumber == 1
        }
    }

    fun startLive(liveParams: HashMap<String, Any?>, noticeList: ArrayList<HashMap<String,Int?>>) {
        rxHttpRequest {
            onRequest = {
                liveInfoDto.value =  TalentLiveRepository.startLive(liveParams, noticeList).await()
            }
            onError = {
                XToast.normal(it.msg)
            }
            isShowDialogRequest = true
        }
    }
}
